<template>
    <div class="icons">
      <swiper  :options="swiperOption" v-if="showIconList">
        <swiper-slide class="swiperSlide" v-for="(page,index) in pages" :key="index">
          <div class="icon"  v-for="item in page" :key="item.id">
            <div class="icon-img">
              <img class="icon-img-content" :src="item.imgUrl">
            </div>
            <p class="icon-desc">{{item.desc}}</p>
          </div>
        </swiper-slide>
        <div class="swiper-pagination" style="bottom:0;" slot="pagination"></div>
      </swiper>
    </div>
</template>
<script>
export default {
  name: 'HomeIcons',
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination', // 分页样式
        autoplay: false // 等同于以下设置
      }
    }
  },
  props: {
    iconList: Array
  },
  computed: {
    pages () {
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8) // floor 向下取整
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    },
    showIconList () {
      return this.iconList.length
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  @import '~styles/mixins.styl'
  .icons >>> .swiper-container
    height: 0
    overflow: hidden
    padding-bottom: 50%
    padding-top: .2rem
  .icons
    height: 0
    overflow: hidden
    padding-bottom: 50%
  .icon
    float: left
    width: 25%
    height: 0
    overflow: hidden
    padding-bottom: 25%
    position: relative
    .icon-img
      position: absolute
      top: 0
      right: 0
      left: 0
      bottom: .44rem
      .icon-img-content
        display: block
        margin: 0 auto
        height: 75%
    .icon-desc
      text-align: center
      height: .44rem
      line-height: .44rem
      color: $darkTextColor
      position: absolute
      left: .05rem
      bottom: .3rem
      right: .05rem
      ellipsis()
</style>
